package org.loofer.ext.component.info;

import android.os.StatFs;
import java.io.File;
import org.apache.log4j.helpers.DateLayout;

public class StorageInfo {
    private long availableSize;
    private File rootPath;
    private long totalSize;

    public File getRootPath() {
        return this.rootPath;
    }

    public void setRootPath(File rootPath) {
        this.rootPath = rootPath;
    }

    public long getTotalSize() {
        return this.totalSize;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    public long getAvailableSize() {
        return this.availableSize;
    }

    public void setAvailableSize(long availableSize) {
        this.availableSize = availableSize;
    }

    public static StorageInfo fromFile(File path) {
        StorageInfo info = new StorageInfo();
        info.setRootPath(path);
        try {
            StatFs fileSystem = new StatFs(path.getAbsolutePath());
            long blockSize = (long) fileSystem.getBlockSize();
            long availableBlocks = (long) fileSystem.getAvailableBlocks();
            info.setTotalSize(((long) fileSystem.getBlockCount()) * blockSize);
            info.setAvailableSize(availableBlocks * blockSize);
        } catch (Exception e) {
            info.setAvailableSize(0);
            info.setTotalSize(0);
        }
        return info;
    }

    public String toString() {
        String str = "[%s : %d / %d]";
        Object[] objArr = new Object[3];
        objArr[0] = this.rootPath == null ? DateLayout.NULL_DATE_FORMAT : this.rootPath.getAbsolutePath();
        objArr[1] = Long.valueOf(getAvailableSize());
        objArr[2] = Long.valueOf(getTotalSize());
        return String.format(str, objArr);
    }
}
